package com.it.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.it.domain.Customer;

import org.apache.ibatis.annotations.*;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface CustomerMapper extends BaseMapper<Customer> {
    //获取所有客户
    @Select("SELECT * FROM customer")
    List<Customer> selectAll();
    //获取单个客户
    @Select("SELECT * FROM customer WHERE customer_id = #{id}")
    Customer selectById(Integer id);
    //创建客户
    @Insert("INSERT INTO customer (name, contact_person, contact_email, contact_phone, address, create_by, update_by) " +
            "VALUES (#{name}, #{contactPerson}, #{contactEmail}, #{contactPhone}, #{address}, #{createBy}, #{updateBy})")
    @Options(useGeneratedKeys = true, keyProperty = "customerId")
    int insert(Customer customer);
    //更新客户
    @Update("UPDATE customer SET name=#{name}, contact_person=#{contactPerson}, " +
            "contact_email=#{contactEmail}, contact_phone=#{contactPhone}, address=#{address}, " +
            "update_by=#{updateBy} WHERE customer_id=#{customerId}")
    int update(Customer customer);
    //删除客户
    @Delete("DELETE FROM customer WHERE customer_id=#{id}")
    int delete(Integer id);

}
